<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller {

	public function __construct()
    {
        parent::__construct();
		$this->load->model('Article_model','article_model');
		$this->load->model('Manager_model','manager_model');
    }
	
	//首页
	public function index(){
		$data['info'] = $this->manager_model->getsysinfo();
		$res = $this->article_model->getrightart();
		$data['article']=$res->result();
		$this->load->view('index/index.html',$data);
	}

	//首页加载更多文章
	public function postart(){
		$num = $this->input->post('num');
		$page = 10;//每次取多少条
		$num = ($num-1)*$page+11;
		$res = $this->article_model->getrightart($page,$num);
		if($res){
			echo json_encode($res->result_array());	
		}
	}


	//根据ID获取文章页
	public function article($id){
		$data['info'] = $this->manager_model->getsysinfo();
		$res = $this->article_model->getartbyid($id);
		$res1 = $this->article_model->getartbyid($id-1);//上一篇
		$res2 = $this->article_model->getartbyid($id+1);//下一篇
		$this->load->model('manager_model');

		if($res->row()){
			$data['article'] = $res->row();
			$data['pre_art'] = $res1->row();
			$data['next_art'] = $res2->row();
			//获取文章分类
			$data['cate'] = $this->article_model->getcateformid($data['article']->cate)->row();
			//获取文章作者
			$data['witter'] = $this->manager_model->getsta($data['article']->uid);
			$this->load->view('index/article.html',$data);
		}else{
			show_404();
		}
		
	}

	//文章分类页
	public function catepage($id=0){
		$data['cate'] = $this->article_model->getcate()->result();
		if($id==0){
			$res = $this->article_model->getallart();
			$data['article']=$res->result();
		}else{
			$res = $this->article_model->getcateart($id);
			$data['article']=$res->result();
			$data['thiscate']=$this->article_model->getcateformid($id)->row();			
		}
		
		$this->load->view('index/catepage.html',$data);
	}

	//关于我
	public function aboutme(){
		$this->load->view('index/aboutme.html');
	}

	//留言板
	public function message(){
		$this->load->view('index/message.html');
	}


}